package ru.rchervot.sanasar.client.place;

import ru.rchervot.sanasar.client.model.FactoryQueryCandidates;
import ru.rchervot.sanasar.client.rpc.RPCServiceAsync;
import ru.rchervot.sanasar.client.view.FactoryModuleCandidates;
import ru.rchervot.sanasar.client.view.RootPresenter;

import com.google.gwt.event.shared.HandlerManager;

public class PlaceSearchCandidates extends AbstractPlaceSearch {
	
	protected static String getPlaceModule() {
		return Constants.MODULE_CAND;
	}
	
	public static String historyTokenDefault() {
		return getPlaceModule() + 
		(getPlaceName() != null
				? Constants.DELIMITER + getPlaceName()
				: ""
		) + Constants.DELIMITER;
	}
	
	private final FactoryModuleCandidates factoryModule;
	
	public PlaceSearchCandidates(HandlerManager eventBus, 
			RPCServiceAsync service, FactoryQueryCandidates factoryQuery,
			RootPresenter  rootPresenter, FactoryModuleCandidates factoryModule) {
		super(eventBus, service, getPlaceModule(), factoryQuery,
				rootPresenter);
		
		this.factoryModule = factoryModule;
	}

	@Override
	protected void attachPlaceToRoot() {
		rootPresenter.showModuleCandidates(factoryModule.getViewForPlaceSearch());
	}
	
//	public static PlaceSearchByQueryIdCandidates build(HandlerManager eventBus, 
//			RPCServiceAsync service, String historyToken) {
//		int[] a = getFirstIntParamAndOffset(historyToken);
//		
//		return new PlaceSearchByQueryIdCandidates(eventBus, service, a[0], a[1]);
//	}
	
//	@Override
//	public EventPlaceChange<?> getEvent() {
//		return new EventPlaceChange<PlaceSearchCandidates>(this);
//	}
	
	@Override
	protected String historyTokenHead() {
		return historyTokenDefault();
	}
}
